package lablayer.view.additional.toolpanelstates;

import javafx.scene.Node;
import javafx.scene.layout.Panel;
import javafx.scene.layout.HBox;
import javafx.scene.shape.Rectangle;
import javafx.scene.paint.Color;
import javafx.scene.input.MouseEvent;
import javafx.scene.control.Button;
import lablayer.view.ViewBox;
import lablayer.view.stat.ViewBoxBuffer;
import lablayer.view.ViewLink;

/**
 * @author Darkness
 */

public class ViewToolLinks extends ViewTool {
    init {
        this.id = ViewTool.LinkId;
    }

    override public function create(): Node {
        Panel {
            content: [
                HBox {
                    content: [
                        Rectangle {
                            width: 75
                            fill: Color.TRANSPARENT
                        },
                        Button {
                            text: "Добавить связь"
                            onMouseClicked: function(e: MouseEvent): Void {
                                var viewBox: ViewBox = ViewBoxBuffer.getViewBox();
                                var x: Float = viewBox.getViewComponentCoordinates().x;
                                var y: Float = viewBox.getViewComponentCoordinates().y;
                                var com: ViewLink = ViewLink {
                                    startX: x
                                    startY: y
                                    endX: x + 100
                                    endY: y
                                };
                                viewBox.addViewComponent(com);
                            }
                        },
						Rectangle {
							width: 5
							height: 5
							fill: Color.TRANSPARENT
						},
						Button {
							text: "Получить XML"
							onMouseClicked: function(e: MouseEvent): Void {
								ViewBoxBuffer.getViewBox().saveToXML();
							}
						},
						Rectangle {
							width: 5
							height: 5
							fill: Color.TRANSPARENT
						},
						Button {
							text: "Загрузить XML"
							onMouseClicked: function(e: MouseEvent): Void {
								ViewBoxBuffer.getViewBox().loadFromXML("llworkspace.xml");
							}
						}
                    ]
                }//end HBox
            ]
        }
    }
}
